package com.ft.oa.web.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ft.oa.domain.customer.CustomerSupplier;
import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.service.customer.CustomerSupplierService;
import com.ft.oa.web.customer.rq.CustomerSupplierPage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/customer/supplier")
public class CustomerSupplierController {

    @Resource
    private CustomerSupplierService customerSupplierService;

    /**
     * 查询供应商列表
     * @param customerSupplierPage
     * @return
     */
    @PostMapping("/list")
    public ApiResult selectCustomerSupplier(@RequestBody CustomerSupplierPage customerSupplierPage){
        Page<CustomerSupplier> supplierPage = customerSupplierService.selectCustomerSupplier(customerSupplierPage);
        return ApiResult.successWithData(supplierPage);
    }

    /**
     * 添加供应商信息
     * @param customerSupplier
     * @return
     */
    @PostMapping("/insert")
    public ApiResult insertCustomerSupplier(@RequestBody CustomerSupplier customerSupplier){
        customerSupplierService.insertCustomerSupplier(customerSupplier);
        return ApiResult.simpleSuccess();
    }

    /**
     * 修改供应商信息
     * @param customerSupplier
     * @return
     */
    @PostMapping("/update")
    public ApiResult updateCustomerSupplier(@RequestBody CustomerSupplier customerSupplier){
        customerSupplierService.updateCustomerSupplier(customerSupplier);
        return ApiResult.simpleSuccess();
    }

    /**
     * 删除供应商信息
     * @param customerSupplier
     * @return
     */
    @PostMapping("/delete")
    public ApiResult deleteCustomerSupplier(@RequestBody CustomerSupplier customerSupplier){
        customerSupplierService.deleteCustomerSupplier(customerSupplier);
        return ApiResult.simpleSuccess();
    }

    /**
     * 根据ID查询供应商详情
     * @param customerSupplier
     * @return
     */
    @PostMapping("/sel")
    public ApiResult selectById(@RequestBody CustomerSupplier customerSupplier){
        CustomerSupplier supplier = customerSupplierService.selectById(customerSupplier);
        return ApiResult.successWithData(supplier);
    }
}
